package com.benew.ntt.ydeval.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EvalUtils {
   /**
    * 获取签名
    * @param string
    * @return
    */
   public static String getDigest(String string) {
      if (string == null) {
         return null;
      }
      char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
      byte[] btInput = string.getBytes(StandardCharsets.UTF_8);
      try {
         MessageDigest mdInst = MessageDigest.getInstance("SHA-256");
         mdInst.update(btInput);
         byte[] md = mdInst.digest();
         int j = md.length;
         char[] str = new char[j * 2];
         int k = 0;
         for (byte byte0 : md) {
            str[k++] = hexDigits[byte0 >>> 4 & 0xf];
            str[k++] = hexDigits[byte0 & 0xf];
         }
         return new String(str);
      } catch (NoSuchAlgorithmException e) {
         return null;
      }
   }


}
